 #include<stdio.h>
 #include<math.h>
 #define max 1000
 main()
 {
 	float r,a = 0,b = 1,h,Tans,Sans,Sans1,SumExtreme = 0,SumRemaining = 0,SumOdd=0,SumEven=0,Sum3=0,Sumnot3=0;
 	int i,j,ch,n;
	
	while(1)
	{
	printf("\n 1. Integra of (1/(1+x^2)) .");
	printf("\n 2. Integra of sqrt(r^2-x^2) .");
	printf("\n Enter your choice (1 or 2 and 0 to exit) :");
	scanf("%d",&ch);
	switch(ch)
	{
 	case 1 :
		Tans=0;Sans=0;Sans1=0;SumExtreme = 0;SumRemaining = 0;
		SumOdd=0;SumEven=0;Sum3=0;Sumnot3=0;
		printf("\n Please enter the number of interval :");
		scanf("%d",&n);
		float Fx[max],X[max];

		h = (float)1/(float)n ;
		printf("\n%f\n",h);
		a = 0;
	 	for(i = 0;i < n+1 ;i++)
	 	{
	 	 X[i] = a;
	 	 a = a+ h;
		 Fx[i] = (float)1/(float)(1+(float)X[i]*(float)X[i]);
		 printf("\n%f",Fx[i]);
	  	}
		//SumExtreme = Fx[0]+Fx[n];
		for( j=0; j < n+1 ;j++)
		{
 			if(j == 0 || j== n)
			{
				SumExtreme = Fx[0]+Fx[n];
			}
			else
			{
			
				SumRemaining = SumRemaining + Fx[j];


				if(j %3 == 0)
				Sum3 = Sum3 + Fx[j] ;
				else
				Sumnot3 = Sumnot3 + Fx[j] ;


				if( j % 2 == 0)
				SumEven = SumEven + Fx[j] ;
				else
				SumOdd = SumOdd + Fx[j] ;
			  }
		}
		printf("\nSumExtreme =%f",SumExtreme);
		printf("\nSumRemain =%f",SumRemaining);
		printf("\nSumOdd =%f",SumOdd);
		printf("\nSumEven =%f",SumEven);
		printf("\nSum3 =%f",Sum3);
		printf("\nSumnot3 =%f",Sumnot3);
		Tans = 4 * (h/2)*( (SumExtreme)+2* (SumRemaining)) ;
		printf("\n The final answer = %f By Trapazoidal rule.",Tans);
		Sans = 4 *  (h/3)* ((SumExtreme)+(4*(SumOdd)+ (2*(SumEven))));
		printf("\n The final answer = %f By Simpsons (1/3)rd  rule.",Sans);
		Sans1 = 4 *3* (h/8)*((SumExtreme)+ (3*(Sumnot3)+ (2 * (Sum3))));
		printf("\n The final answer = %f By Simpsons (3/8)th  rule.",Sans1);
		break;
	case 2 :
		Tans=0;Sans=0;Sans1=0;SumExtreme = 0;SumRemaining = 0;
		SumOdd=0;SumEven=0;Sum3=0;Sumnot3=0;
		//printf("\nEnter Radious of Circle :");
		//scanf("%f",&r);
		printf("\n Please enter the number of interval :");
		scanf("%d",&n);
		printf("\nPlease enter the radius :");
		scanf("%f",&r);
		float Fx1[max],X1[max];

		h = (float)1/(float)n ;
		printf("\n%f\n",h);
		a = 0;
	 	for(i = 0;i < n+1 ;i++)
	 	{
	 	 X1[i] = a;
	 	 a = a+ h;
		 Fx1[i] = sqrt((float)(r*r - (float)X1[i]*(float)X1[i]));
		 printf("\n%f",Fx1[i]);
	  	}
		//SumExtreme = Fx[0]+Fx[n];
		for( j=0; j < n+1 ;j++)
		{
 			if(j == 0 || j== n)
			{
				SumExtreme = Fx1[0]+Fx1[n];
			}
			else
			{
			
				SumRemaining = SumRemaining + Fx1[j];


				if(j %3 == 0)
				Sum3 = Sum3 + Fx1[j] ;
				else
				Sumnot3 = Sumnot3 + Fx1[j] ;


				if( j % 2 == 0)
				SumEven = SumEven + Fx1[j] ;
				else
				SumOdd = SumOdd + Fx1[j] ;
			  }
		}
		printf("\nSumExtreme =%f",SumExtreme);
		printf("\nSumRemain =%f",SumRemaining);
		printf("\nSumOdd =%f",SumOdd);
		printf("\nSumEven =%f",SumEven);
		printf("\nSum3 =%f",Sum3);
		printf("\nSumnot3 =%f",Sumnot3);
		Tans = ((float)1/r)*4 * (h/2)*(float)( (SumExtreme)+2* (SumRemaining)) ;
		printf("\n The final answer = %f By Trapazoidal rule.",Tans);
		Sans = ((float)1/r)*4 *  (h/3)* ((SumExtreme)+((float)4*(SumOdd)+ (2*(SumEven))));
		printf("\n The final answer = %f By Simpsons (1/3)rd  rule.",Sans);
		fflush(stdin);
		Sans1 = ((float)1/r)*4 *3* (h/8)*((SumExtreme)+ ((float)3*(Sumnot3)+ (2 * (Sum3))));
		printf("\n The final answer = %f By Simpsons (3/8)th  rule.",Sans1);
		break;
	default : 
		printf("BYE");
		exit(0);
	}
	}
}
